#include <iostream>
#include <deque>
#include <vector>

struct data { int u, v, c; };
struct edge { int v, c; };
int const inf = 1<<27;
int const maxn = 1002;
std::vector<data> da;
int map[maxn][maxn];
int n, p, k;

int spfa(int source, int target)
{
	int dist[n];
	bool vis[n];
	std::fill(dist, dist+n, inf);
	std::fill(vis, vis+n, false);
	std::deque<int> relaxed;
	relaxed.push_back(source);
	dist[source] = 0;
	vis[source] = true;

	while (!relaxed.empty()) {
		int u = relaxed.front();
		relaxed.pop_front();
		vis[u] = false;
		for (int v = 0; v < n; v++) {
			if (map[u][v] != -1 && dist[v] > dist[u] + map[u][v]) {
				dist[v] = dist[u] + map[u][v];
				if (!vis[v]) {
					if (!relaxed.empty() && dist[v] < dist[relaxed.front()])
						relaxed.push_front(v);
					else
						relaxed.push_back(v);
					vis[v] = true;
				}
			}
		}
	}
	return dist[target];
}

bool judge(int x)
{
	for (int i = 0; i < n; i++)
		for (int j = 0; j < n; j++) map[i][j] = -1;

	for (int i = 0; i < p; i++)
		map[da[i].u][da[i].v] = map[da[i].v][da[i].u] = int(da[i].c > x);

	if (spfa(0, n-1) <= k) return true;
	return false;
}

int main()
{
	std::ios::sync_with_stdio(false);
	std::cin >> n >> p >> k;
	da.resize(p);
	int max_c = 0;
	for (int i = 0; i < p; i++) {
		std::cin >> da[i].u >> da[i].v >> da[i].c;
		da[i].u--;  da[i].v--;
		max_c = std::max(max_c, da[i].c);
	}

	int l = 0, r = max_c;
	if (!judge(max_c)) { std::cout << "-1\n"; return 0; }
	while (l+1 < r) {
		int mid = (l+r)/2;
		if (judge(mid)) r = mid;
		else            l = mid + 1;
	}
	if (judge(l)) r = l;
	std::cout << r << "\n";
}

